<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img {
            width: 300px;
        }
    </style>
</head>

<body>
    <button id="ldh">刘德华</button>
    <button id="fj">风景</button>
    <img src="D:\code\img\ldh.jpeg" alt="" title="刘德华">
    <script>
        //修改元素属性 src
        //1.获取元素
        var ldh = document.getElementById('ldh');
        var fj = document.getElementById('fj');
        var img = document.querySelector('img');
        //2.注册事件
        fj.onclick = function() {
            img.src = 'D:/code/img/风景.jpg';
            img.title = '风景';
        }
        ldh.onclick = function() {
            img.src = 'D:/code/img/ldh.jpeg';
            img.title = '刘德华';
        }
    </script>
</body>

</html>